export const editorPropsMap = {
    /** 输入框 */
    input: 'input',
    /** 数字输入框 */
    inputNumber: 'InputNumber',
    /** 颜色选择器 */
    color: 'color',
    /** 下拉选择器 */
    select: 'select',
    /** 表格 */
    table: 'table',
    /** 开关 */
    switch: 'switch',
    /** 模型绑定选择器 */
    modelBind: 'ModelBind',
    /** 可拖拽项 */
    crossSortable: 'CrossSortable'
}


/*---------------------------------------modelBind-------------------------------------------*/

export function createEditorModelBindProp({
    label = '字段绑定',
    defaultValue,
    tips
}) {
    return {
        type: editorPropsMap.modelBind,
        label,
        tips,
        defaultValue
    }
}

/*---------------------------------------switch-------------------------------------------*/
export function createEditorSwitchProp({
    label,
    defaultValue,
    tips
}) {
    return {
        type: editorPropsMap.switch,
        label,
        tips,
        defaultValue
    }
}

/*---------------------------------------input-------------------------------------------*/

export function createEditorInputProp({
    label,
    defaultValue,
    tips
}) {
    return {
        type: editorPropsMap.input,
        label,
        tips,
        defaultValue
    }
}
/*---------------------------------------InputNumber -------------------------------------------*/

export function createEditorInputNumberProp({
    label,
    defaultValue,
    max,
    min,
    tips
}) {
    return {
        type: editorPropsMap.inputNumber,
        label,
        tips,
        max,
        min,
        defaultValue
    }
}

/*---------------------------------------color-------------------------------------------*/

export function createEditorColorProp({ label, defaultValue }) {
    return {
        type: editorPropsMap.color,
        label,
        defaultValue
    }
}

/*---------------------------------------select-------------------------------------------*/

export function createEditorSelectProp({
    label,
    options,
    defaultValue,
    tips,
    multiple
}) {
    return {
        type: editorPropsMap.select,
        label,
        defaultValue,
        tips,
        options,
        multiple
    }
}

/*---------------------------------------table-------------------------------------------*/

export function createEditorTableProp({
    label,
    option,
    defaultValue
}) {
    return {
        type: editorPropsMap.table,
        label,
        table: option,
        defaultValue
    }
}

/*---------------------------------------CrossSortableOptions-------------------------------------------*/

export function createEditorCrossSortableProp({
    label,
    labelPosition,
    multiple,
    showItemPropsConfig,
    defaultValue
}) {
    return {
        type: editorPropsMap.crossSortable,
        label,
        multiple,
        showItemPropsConfig,
        labelPosition,
        defaultValue
    }
}

// 
export const createDotProp = (originObj, propName) => {
    const props = propName.split('.')
    const isDotProp = props.length > 1
    const prop = props.pop()
    const propObj = props.reduce((prev, curr) => (prev[curr] ??= {}), originObj)
    return {
      prop,
      propObj,
      isDotProp
    }
  }
